package stream;

import java.util.*;
import java.util.stream.Stream;

/**
 * 创建流
 *
 * @author <a href="mailto:mojo_jj@163.com">Mojo</a>
 */
public class Stream01 {
    public static void main(String[] args) {
        ////List,Set创建流
        //createStreamByArray();
        //createStreamByList();
        //createStreamBySet();
        createStreamByMap();
    }

    private static void createStreamByMap() {
        Map<Object, Object> map = new HashMap<>();
        map.put(1, "a");
        map.put(2, "b");
        map.put(3, "c");
        map.entrySet().stream().forEach(System.out::println);
        System.out.println(">>>>>>>");
        map.values().stream().forEach(System.out::println);

    }

    private static void createStreamBySet() {
        Set<Object> set = new HashSet<>();
        set.add("1");
        set.add("2");
        set.add("3");
        set.add("a");
        set.add("b");
        set.forEach(System.out::print);
    }

    private static void createStreamByArray() {
        Object[] objects = {1, 2, 3, "a", "b", "c"};
        Stream<Object> stream = Arrays.stream(objects);
        stream.forEach(System.out::println);
    }

    private static void createStreamByList() {
        List<Object> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add("a");
        list.add("b");
        Stream<Object> stream = list.stream();
        stream.forEach(System.out::print);
    }
}
